﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using DXTools.UI.Core;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Unity;
using DXTools.UI.Core.Events;
using DXTools.UI.Core.ViewModel;

namespace DXTools.UI.Shell
{
    public class MainShellViewModel : ViewModelBase
    {
        private bool _showWelcomeImage = true;
        public bool ShowWelcomeImage 
        {
            get
            {
                return _showWelcomeImage;
            }
            private set
            {
                _showWelcomeImage = value;
                RaisePropertyChanged("ShowWelcomeImage");
            }
        }

        public MainShellViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer container)
            : base(regionManager, eventAggregator, container)

        {
            eventAggregator.GetEvent<ViewClosedEvent>().Subscribe(OnViewClosed);
            eventAggregator.GetEvent<ViewAddedEvent>().Subscribe(OnViewAdded);
        }

        public void OnViewClosed(UserControl view)
        {
            int i = 0;
            foreach (var v in RegionManager.Regions[RegionNames.BODY_REGION].Views)
                i++;
            if (i == 0)
                ShowWelcomeImage = true;

        }

        public void OnViewAdded(UserControl view)
        {
            ShowWelcomeImage = false;
        }

    }
}
